//frame dragging
var indicatorBar;
var frameDrag=null;
var frameDragInner=null;
var topWindow=null;//top window
var offy=0;
var offx=0;

document.ondragstart=function(){return false;};

function init(){
	indicatorBar=document.getElementById("indicatorBar");
	topWindow=document.getElementById("frame_Chat");
	topWindow.style.zIndex=10;
}

document.addEventListener("mouseup",function(event){
	if(frameDrag!=null){
		frameDragInner.style.display="block";
	}
	frameDrag=null;
	frameDragInner=null;
});
document.addEventListener("mousedown",function(event){
	if(event.target.id.indexOf("head", 0)>-1){
		frameDrag=event.target.parentNode;
		
		frameDragInner=document.getElementById("iframe_"+frameDrag.id);
		frameDragInner.style.display="none";
		
		
		offy=event.pageY-frameDrag.offsetTop;
		offx=event.pageX-frameDrag.offsetLeft;
		//top
		if(topWindow==null){
			topWindow=frameDrag;
		}
		//
		if(topWindow!=frameDrag){
			topWindow.style.zIndex=1;
			topWindow=frameDrag;
			topWindow.style.zIndex=10;
		}
	}
});

document.addEventListener("mousemove",function(event){
	if(frameDrag!=null){
		with(frameDrag.style){
			left=(event.pageX-offx)+"px";
			top=(event.pageY-offy)+"px";
		}
		return false;
	}else{
		if(event.pageX>(document.body.offsetWidth-20)){
			indicatorBar.style.marginLeft=-indicatorBar.offsetWidth+"px";
			indicatorBar.style.opacity=1;
		}else if(event.pageX<(document.body.offsetWidth-indicatorBar.offsetWidth)){
			indicatorBar.style.marginLeft=0+"px";
			indicatorBar.style.opacity=0;
		}
	}
});

//expand/minimize/maximize frame
function minimizeFrame(frame){
	frame.style.opacity=0;
	setTimeout(function(){
		frame.style.visibility="hidden";
	},1000);
}

function expandFrame(frameId){
	var frame=document.getElementById(frameId);
	if((topWindow!=frame)||(frame.style.visibility=="hidden")){
		if(topWindow!=null){
			topWindow.style.zIndex=1;
		}
		topWindow=frame;
		topWindow.style.zIndex=10;
		frame.style.visibility="visible";
		frame.style.opacity=1;
	}else{
		minimizeFrame(frame);
	}
}

function reloadFrame(frameId){
	var frame=document.getElementById(frameId);
	frame.src=frame.src;
}



//boardFrame
function handleKey(input, event){
	if((event.keyCode==13)&&(input.value!="")){
		parent.document.getElementById("iframe_frame_Board").src="Task.jsp?queryFind="+input.value;
	}
}

var shDBMenu=true;
function showHideDBMenu(){
	if(shDBMenu){
		menu=document.getElementById("devboard_menu");
		menu.style.opacity=1;
		menu.style.marginLeft=-(menu.offsetWidth+indicatorBar.offsetWidth)+"px";
		shDBMenu=false;
	}else{
		menu=document.getElementById("devboard_menu");
		menu.style.opacity=0;
		menu.style.marginLeft="0px";
		shDBMenu=true;
	}
};




//ajax
window.addEventListener("beforeunload",function(){
	var request=new XMLHttpRequest();
	request.onreadystatechange=function(){
		if(request.readyState==4){
			if(request.responseText!=""){
				//
			}
		}
	};
	var s="";
	var frames=document.getElementsByTagName("iframe");
	for(var i=0;i<frames.length;i++){
		var dif=frames[i].parentNode;
		s+=dif.id+"=width:"+dif.style.width+";height:"+dif.style.height+";top:"+
			dif.style.top+";left:"+dif.style.left+";visibility:"+dif.style.visibility+";\n";
	}
	request.open("POST","MainHandler?reason=SAVE_PARAMS",true);
	request.send(s);
});
